package com.woniuxy.stage3demo.mapper.kang;

import com.woniuxy.stage3demo.bean.hpd.ProductBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CouProductMapper {

    /**
     * 新增
     * @param couId
     * @param productId
     * @return
     */
    @Insert("insert into cou_product (cou_id,product_id,del_flag) values (#{c},#{p},0)")
    int addCouProduct(@Param("c")Long couId,@Param("p")Long productId);

    /**
     * 删除（删除标记的修改）
     * @param id
     * @return
     */
    @Update("update cou_product set del_flag = 1 where id = #{id}")
    int deleteCousProduct(@Param("id")int id);

    /**
     * 分页查询
     * @param id
     * @return
     */
    @ResultType(ProductBean.class)
    @Select("select c.id,p.product_name productName,p.product_num productNum from cou_product c,product p " +
            "where p.id = c.product_id and c.cou_id = #{id} and c.del_flag = 0")
    List<ProductBean> findLimit(@Param("id")int id);

    /**
     * 判断是否存在
     * @return
     */
    @Select("select count(*) from cou_product where del_flag = 0 and cou_id = #{c} and product_id = #{p}")
    int isExist(@Param("c")Long couId,@Param("p")Long productId);

}
